<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" placeholder="请输入用户的编号" id="num">
    <input type="button" value="查询" onclick="sendAjax()">
    <div id="mydiv"></div>
    <script>
        function sendAjax() {
            let mydiv = document.getElementById("mydiv");
            let num = document.getElementById("num").value;
            let xhr = new XMLHttpRequest();
            xhr.open("get", `/queryUser/${num}`);
            xhr.onload = function () {
                let obj = JSON.parse(xhr.responseText);
                if (obj.flag) {
                    mydiv.innerHTML = obj.user.username + obj.user.password;
                } else {
                    mydiv.innerHTML = "没有查询到该用户";
                }
            };
            xhr.send();
        }
    </script>
</body>

</html>